package cn.iocoder.yudao.module.jifenyuan.controller.admin.walletlog;

import cn.iocoder.yudao.module.jifenyuan.controller.app.walletlog.vo.AppWalletLogRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.jifenyuan.controller.admin.walletlog.vo.*;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.walletlog.WalletLogDO;
import cn.iocoder.yudao.module.jifenyuan.convert.walletlog.WalletLogConvert;
import cn.iocoder.yudao.module.jifenyuan.service.walletlog.WalletLogService;

@Tag(name = "管理后台 - 记分员 钱包记录")
@RestController
@RequestMapping("/jifenyuan/wallet-log")
@Validated
public class WalletLogController {

    @Resource
    private WalletLogService walletLogService;

    @PostMapping("/create")
    @Operation(summary = "创建记分员 钱包记录")
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:create')")
    public CommonResult<Long> createWalletLog(@Valid @RequestBody WalletLogCreateReqVO createReqVO) {
        return success(walletLogService.createWalletLog(WalletLogConvert.INSTANCE.convert(createReqVO)));
    }

    @PutMapping("/update")
    @Operation(summary = "更新记分员 钱包记录")
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:update')")
    public CommonResult<Boolean> updateWalletLog(@Valid @RequestBody WalletLogUpdateReqVO updateReqVO) {
        walletLogService.updateWalletLog(WalletLogConvert.INSTANCE.convert(updateReqVO));
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除记分员 钱包记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:delete')")
    public CommonResult<Boolean> deleteWalletLog(@RequestParam("id") Long id) {
        walletLogService.deleteWalletLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得记分员 钱包记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:query')")
    public CommonResult<AppWalletLogRespVO> getWalletLog(@RequestParam("id") Long id) {
        WalletLogDO walletLog = walletLogService.getWalletLog(id);
        return success(WalletLogConvert.INSTANCE.convert(walletLog));
    }

    @GetMapping("/list")
    @Operation(summary = "获得记分员 钱包记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:query')")
    public CommonResult<List<AppWalletLogRespVO>> getWalletLogList(@RequestParam("ids") Collection<Long> ids) {
        List<WalletLogDO> list = walletLogService.getWalletLogList(ids);
        return success(WalletLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得记分员 钱包记录分页")
    @PreAuthorize("@ss.hasPermission('jifenyuan:wallet-log:query')")
    public CommonResult<PageResult<AppWalletLogRespVO>> getWalletLogPage(@Valid WalletLogPageReqVO pageVO) {
        PageResult<WalletLogDO> pageResult = walletLogService.getWalletLogPage(WalletLogConvert.INSTANCE.convert(pageVO));
        return success(WalletLogConvert.INSTANCE.convertPage(pageResult));
    }



}
